package cn.gmph.blog.service.term.dao;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;
import cn.gmph.blog.service.term.entity.TermTaxonomyDO;
import cn.gmph.blog.service.term.dao.helper.TermTaxonomyProvider;

import java.util.List;;

public interface TermTaxonomyDAO {
    @Results({ @Result(column = "term_taxonomy_id", property = "termTaxonomyId"), @Result(column = "term_id", property = "termId") })
    @Select("SELECT * FROM wp_term_taxonomy ")
    public List<TermTaxonomyDO> findAll();

    @Results({ @Result(column = "term_taxonomy_id", property = "termTaxonomyId"), @Result(column = "term_id", property = "termId") })
    @Select("SELECT * FROM wp_term_taxonomy WHERE term_taxonomy_id = #{id}")
    public TermTaxonomyDO getById(@Param("id") Long id);

    @Insert("INSERT into wp_term_taxonomy(term_taxonomy_id,term_id,taxonomy,description,parent,count) VALUES (#{termTaxonomyId},#{termId},#{taxonomy},#{description},#{parent},#{count})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    public void insert(TermTaxonomyDO termTaxonomy);

    @Delete("DELETE FROM wp_term_taxonomy WHERE id = #{id}")
    public int deleteById(@Param("id") int id);

    @UpdateProvider(type = TermTaxonomyProvider.class, method = "update")
    public int update(@Param("termTaxonomy") TermTaxonomyDO termTaxonomy);

    @Results({ @Result(column = "term_taxonomy_id", property = "termTaxonomyId"), @Result(column = "term_id", property = "termId") })
    @SelectProvider(type = TermTaxonomyProvider.class, method = "pageList")
    public List<TermTaxonomyDO> pageList(@Param("termTaxonomy") TermTaxonomyDO termTaxonomy, @Param("pageNum") Integer pageNum, @Param("pageSize") Integer pageSize);

    @SelectProvider(type = TermTaxonomyProvider.class, method = "pageListCount")
    public Integer pageListCount(@Param("termTaxonomy") TermTaxonomyDO termTaxonomy);

}